Skip to content

Conversation

hasanmo
Copy link
Member

@hasanmo hasanmo commented Oct 16, 2026

Change

Improved the existing authentication flow while keeping the current session-token approach.

  • Added shared Zod schemas for frontend and backend authentication validation.
  • Login now requires a valid email and a non-empty password without applying registration length requirements.
  • Registration validates email, name, password, and frontend password confirmation.
  • Invalid session UUIDs are rejected before PostgreSQL queries.
  • Added structured GraphQL error codes: INVALID_INPUT, INVALID_CREDENTIALS, EMAIL_TAKEN, and RATE_LIMITED.
  • Updated the auth client to use generated Register, Login, CurrentUser, and SignOut operations.
  • Replaced error-message matching with code-based handling.
  • Added safe handling of HTML and invalid JSON responses.
  • Added basic in-memory rate limiting per client address: 10 login attempts and 5 registration attempts per minute.
  • Updated development, Docker, and release configuration to include the shared validation package.
  • Fixed Windows compatibility in the development startup command.

Added focused tests and documentation in docs/auth-improvements.md.

Scope

This PR focuses on authentication. CRUD work remains separate.

Session tokens remain in localStorage, and existing session restoration and protected routes are preserved. HttpOnly cookies and HTTPS are deferred.

No database migration is required.

Verification

  • npm run check passed, including formatting, linting, generated contracts, migration metadata, TypeScript, 212 tests, and production builds.
  • All 12 database checks passed.
  • All 7 browser smoke tests passed using installed Chrome.
  • Verified local frontend/API startup after fixing Windows command quoting.

Tests cover validation boundaries, short existing login passwords, malformed session IDs, session restoration, logout, structured errors, rate limits, and proxy-header handling.

Deployment notes

Set AUTH_TRUST_PROXY=true on the VM when using the documented local Apache proxy. The API should continue listening on 127.0.0.1.

Without this setting, requests through Apache share the same rate-limit bucket. Rate-limit counters are held in memory and reset when the API restarts.

Verify login, registration, refresh, logout, and client-IP forwarding on the VM after deployment.

AI use

AI assisted with implementation, documentation, testing, and code review. Changes were checked with automated tests, type checking, builds, and local startup verification.

@hasanmo hasanmo requested a review from a team as a code owner October 16, 2026 11:25
Copy link
Member

@oliveror oliveror left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identifiserte svakheter

Review er assistert av AI. To svakheter ble identifisert:

High: HttpOnly-cookie/session-context-migreringen er ikke implementert. Session-token lagres fortsatt i localStorage og sendes eksplisitt til currentUser/signOut via GraphQL: store.ts:24, authApi.ts:64, schema.graphql:14, authResolvers.ts:14. Dette beholder XSS-risikoen feedbacken ønsket å fjerne. AuthContext inneholder bare rate-limit-klienten: app.ts:18.

Medium: Testene bekrefter den gamle, usikre kontrakten i stedet for cookie-flyten. API-testene forventer sessionToken i responsen og som argument: authApp.test.ts:68. Web-testene forventer fortsatt token i localStorage: AuthPages.test.tsx:131. Dermed mangler dekning for cookie-basert session restoration, logout og cookie-attributter.

Dekket av branch

Delt Zod-validering, separate login-/registerregler, UUID-validering før databasekall, strukturerte GraphQL-feilkoder, genererte GraphQL-kontrakter og en enkel auth-rate limiter er implementert.

Copy link
Member

@oliveror oliveror left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After reading the scope of the PR closer and discussing with the team, we have decided to postpone HttpOnly-cookie-related issues to next delivery. The branch is therefore approved.

@oliveror oliveror merged commit 48e925b into dev Oct 16, 2026
2 checks passed
olestan pushed a commit that referenced this pull request Oct 16, 2026
Co-authored-by: Hasan Mohammad Fawzi <hasan.fawzi@hoglund.no>
olestan added a commit that referenced this pull request Oct 16, 2026
…delivery docsDev –> Main) (#55)

feat: improve local development, recipe creation, authentication and delivery docs

* Added Docker for local development

* fix(recipes): improve Add Recipe form ([#52](#52))
  * improve Add Recipe form
  * refine image and ingredient handling

* feat(auth): share validation and improve authentication handling ([#53](#53))

* docs: add second delivery progress summary ([#54](#54))
  * add second delivery progress summary

Co-authored-by: Ole Stangeland <olestan@stud.ntnu.no>
Co-authored-by: Hasan Mohammad Fawzi <hasanmo@stud.ntnu.no>
Co-authored-by: Hasan Mohammad Fawzi <hasan.fawzi@hoglund.no>
@oliveror oliveror deleted the hasan/feat/auth-improvements branch October 30, 2026 10:45
Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants